var vm = new Vue({
    el: '#rrapp',
    data: {
        query: {id: null, payNo: null, applyStatus: null},
        page: {currentPage: 0, pageSizes: [20, 50, 100], pageSize: 20, total: 0, ascending: [], descending: []},
        title: null,
        showList: true,
        applyCashData: [],//申请提现记录
        applyStatusList: [],
        detail: {
            applyCash: {},
            applyCashItems: [],
            applyCashLogs: [],
        }
    },
    mounted: function () {
        this.queryApplyCashLog();
    },
    methods: {
        // 查询
        queryApplyCashLog: function () {
            //查询参数
            var queryParam = this.query;

            // 分页参数
            queryParam.page = this.page.currentPage;
            queryParam.limit = this.page.pageSize;

            //排序参数
            queryParam.ascending = this.page.ascending;
            queryParam.descending = this.page.descending;

            //ajax 请求
            $.ajax({
                type: "POST",
                url: baseURL + "capital/merchantapplycash/applyCashLog",
                contentType: "application/json;charset=UTF-8",
                data: JSON.stringify(queryParam),
                success: function (r) {
                    if (r.code == 0) {
                        vm.page.total = r.page.totalCount;
                        vm.applyCashData = r.page.list;
                        vm.applyStatusList = r.userData.applyStatusEnum;
                    } else {
                        alert(r.msg);
                    }
                }
            });


        },

        searchApplyCashLog : function () {
            this.page.currentPage = 1;
            this.queryApplyCashLog();
        },

        // 页数变化
        handleSizeChange: function (val) {
            this.page.pageSize = val;
            this.queryApplyCashLog();
        },
        //当前页变化
        handleCurrentChange: function (val) {
            this.page.currentPage = val;
            this.queryApplyCashLog();
        },

        // 页数变化
        handleSizeChange: function (val) {
            this.page.pageSize = val;
            this.queryApplyCashLog();
        },

        sortChange: function (column) {
            if (column.order === 'ascending') {
                if (this.page.ascending.indexOf(column.column.index) == -1) {
                    this.page.ascending.push(column.column.index);
                }
                if (this.page.descending.indexOf(column.column.index) > -1) {
                    this.page.descending.splice(this.page.descending.indexOf(column.column.index), 1);
                }
            }
            if (column.order === 'descending') {
                if (this.page.descending.indexOf(column.column.index) == -1) {
                    this.page.descending.push(column.column.index);
                }
                if (this.page.ascending.indexOf(column.column.index) > -1) {
                    this.page.ascending.splice(this.page.ascending.indexOf(column.column.index), 1);

                }
            }

            if (column.order === null) {
                if (this.page.descending.indexOf(column.column.index) > -1) {
                    this.page.descending.splice(this.page.descending.indexOf(column.column.index), 1);
                }
                if (this.page.ascending.indexOf(column.column.index) > -1) {
                    this.page.ascending.splice(this.page.ascending.indexOf(column.column.index), 1);
                }

            }

            this.queryApplyCashLog();
        },

        //查看明细
        lookDetail: function (id) {
            vm.showList = false;
            // 异步加载 明细相关数据
            $.get(baseURL + "capital/merchantapplycash/info/" + id, function (r) {
                if(r.code == 0){
                    vm.detail.applyCash = r.merchantApplyCash;
                    vm.detail.applyCashItems = r.merchantApplyCashItems;
                    vm.detail.applyCashLogs = r.merchantApplyLog;
                }else {
                    alert(r.msg);
                }

            });

        },

        goBack: function () {
            vm.showList = true;
            this.queryApplyCashLog();
        }

    },


});